package com.lottery.ruok.lottrey.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetWinningResponse;
import com.lottery.ruok.lottrey.ui.widget.VerticalSwitchView;

import java.util.List;

public class VerticalSwitchViewAdapter {

    protected List<GetWinningResponse> mDatas;

    public VerticalSwitchViewAdapter(List<GetWinningResponse> datas) {
        this.mDatas = datas;
    }

    public void setData(List<GetWinningResponse> datas) {
        this.mDatas = datas;
    }

    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public View onCreateView(VerticalSwitchView parent) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.rank_item1, null);
    }

    public void onBindView(View view, final int position) {
        GetWinningResponse response = mDatas.get(position);

        TextView name = view.findViewById(R.id.name);
        TextView result = view.findViewById(R.id.result);
        TextView type = view.findViewById(R.id.type);
        name.setText(response.getUsername());
        result.setText(response.getProfit());
        type.setText(response.getName());
    }

    public void refreshData(LinearLayout parent, List<GetWinningResponse> winners){
        for(int i=0; i<parent.getChildCount(); i++) {
            View child = parent.getChildAt(i);
            TextView name = child.findViewById(R.id.name);
            TextView result = child.findViewById(R.id.result);
            TextView type = child.findViewById(R.id.type);
            name.setText(winners.get(i).getUsername());
            result.setText(winners.get(i).getProfit());
            type.setText(winners.get(i).getName());
        }
    }

}
